#include <stdio.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <string.h>
#include <sys/stat.h>
#include <errno.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <sys/wait.h>
#include <pthread.h>
#include <sys/select.h>
#include "common.h"
#include "client.h"

int main()
{
	int socketed=-1,connected=-1, ret=-1;
	struct sockaddr_in server_addr;
	int retlog=-1;
	int i;
	int p;
	PK_REQUEST  rrq;
	PK_DATA     data;
	PK_ACK      ack;
	PK_ERROR    ero;
	PK_IFLIVE   live;
	
	memset(&server_addr,0,sizeof(server_addr));
	memset(&rrq,0,sizeof(rrq));
	memset(&data,0,sizeof(data));
	memset(&ack,0,sizeof(ack));
	memset(&ero,0,sizeof(ero));
	memset(&live,0,sizeof(live));

	server_addr.sin_family=AF_INET;
	server_addr.sin_port=htons(2005);
	server_addr.sin_addr.s_addr=INADDR_ANY;

	

	socketed=socket(AF_INET,SOCK_STREAM,0);
	if(socketed<0)
	{
		perror("error socket - ");
		return -1;
	}
	
	connected=connect(socketed,(struct sockaddr *)&server_addr,sizeof(struct sockaddr_in));
	if(connected<0)
	{
		perror("error connect - ");
		close(socketed);
		return -1;
	}
	
	do{
		retlog=login(&rrq,socketed);
		if(retlog==-1) 
		{	
			printf("exit\n");
			exit(0);
		}
		if(retlog==1)
		{
			printf("welcome!\n");
			break;
		}
	}while(1);
	while(1)
	{
		
	}

	close(connected);
	close(socketed);
	return 0;
}

